var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        stationOrderId:''
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
        this.params.stationOrderId = Pub.getSession('stationOrderId');
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            stationOrderId:_this.params.stationOrderId
        };
        console.log(paramsObj);
        Api.expressorderlistdetails(paramsObj, function(data){
            console.log(data);
            var list=data.list;
            var data=data.data;

            console.log(list);
            $('#orderSn').text(data.orderSn);
            $('#expressOrderSn').text(data.expressOrderSn);
            $('#gmtcCreate').text(data.gmtcCreate);
            $('#doorTime').text(data.doorTime[0]+'~'+data.doorTime[1]);
            // $('#orderState').text(data.orderState);
            $('#protectPrice').text('￥'+data.protectPrice);
            $('#itemType').text(data.itemType);
            $('#itemWeight').text(data.itemWeight+'公斤');

            $('#send_name').text(data.senderInfo.name);
            $('#send_mobile').text(data.senderInfo.phone);
            $('#send_address').text(data.senderInfo.provName+data.senderInfo.cityName+data.senderInfo.countyName+data.senderInfo.streetName+data.senderInfo.address);

            $('#recipient_name').text(data.recipientInfo.name);
            $('#recipient_mobile').text(data.recipientInfo.phone);
            $('#recipient_address').text(data.recipientInfo.provName+data.recipientInfo.cityName+data.recipientInfo.countyName+data.recipientInfo.streetName+data.recipientInfo.address);

            $('#courierRealName').text(data.courierRealName);
            $('#courierMobile').text(data.courierMobile);
            $('#pickCode').text(data.pickCode);
            if (data.courierType=='free') {
                $('#courierType').text('自由快递');
            }else{
                $('#courierType').text('官方快递');
            };

            switch (data.orderState) {
                case -1:
                    $('.state').text('系统取消订单');
                    break;
                case 0:
                    $('.state').text('客户已取消');
                    break;
                case 5:
                    $('.state').text('订单异常');
                    break;
                case 10:
                    $('.state').text('用户下单，待支付，未接单');
                    break;
                case 20:
                    $('.state').text('未支付，已接单');
                    break;
                case 25:
                    $('.state').text('未支付，已取件');
                    break;
                case 30:
                    $('.state').text('已支付，已接单，已取件');
                    break;
                case 40:
                    $('.state').text('已入库');
                    break;
                case 50:
                    $('.state').text('封箱');
                    break;
                case 55:
                    $('.state').text('拆箱');
                    break;
                case 60:
                    $('.state').text('出库');
                    break;
                case 65:
                    $('.state').text('中转');
                    break;
                case 70:
                    $('.state').text('配送员接单');
                    break;
                case 75:
                    $('.state').text('配送员已取件');
                    break;
                case 80:
                    $('.state').text('配送完成');
                    break;
                case 90:
                    $('.state').text('配送员取消');
                    break;
                case 95:
                    $('.state').text('已删除');
                    break;
            }
            _this.getDataList(list);
        });
    },
    getDataList:function(data){
        var _this = this;
        if (data && data.length > 0) {
            var html = '',
                i = 0,
                len = data.length;
            for (i; i < len; i++) {
                html += '<tr>' +
                        '<td class="text-c">' + data[i].operator + '</td>' +
                        '<td class="text-c">' + data[i].operatorMobile + '</td>'+
                        '<td class="text-c">' + data[i].gmtCreate + '</td>';
                switch (data[i].state) {
                    case 20:
                        html += '<td class="text-c">未支付，已接单</td>';
                        break;
                    case 40:
                        html += '<td class="text-c">已入库</td>';
                        break;
                    case 50:
                        html += '<td class="text-c">封箱</td>';
                        break;
                    case 55:
                        html += '<td class="text-c">拆箱</td>';
                        break;
                    case 60:
                        html += '<td class="text-c">出库</td>';
                        break;
                    case 65:
                        html += '<td class="text-c">中转</td>';
                        break;
                }
                html += '<td class="text-c">' + data[i].remark + '</td>' +
                    '</tr>';
            }
            $('#opList').html(html);

        } else {
            var html = '<tr>' +
                '<td class="text-c c-666" colspan="5" >暂无数据</td>' +
                '</tr>';
            $('#opList').html(html);

        }
    },
    addremark:function(){
        var _this = this;
        var remark=$('#remarkVal').val();
        var Params = {
            passport: _this.params.passport,
            stationOrderId:_this.params.stationOrderId,
            remark:remark,
            isPick:1
        };
        console.log(Params);
        Api.addremark(Params, function(data) {
            _this.getData();
            layui.use('layer', function(){
                layer.msg('备注成功', {icon: 6});
            });
            $('#modal_remark').modal('hide');
        })
    },
    otherEvent:function(){
        var _this = this;
        $('.goods-checkbox input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
        $('#remark_order').click(function(event) {
            $('#modal_remark').modal('show');
            $('#remarkVal').val('');
        });
        $('#remarkYes').click(function(event) {
            _this.addremark();
        });
    },
    initEvent: function(){
        var _this = this;
        _this.getData();
        _this.otherEvent();


    }
};
var page = new Page();